import { getCurrentInstance, ref } from "vue";
import initData from "./data";
import { ListDataItem, ChildListItem } from "./interfaces";

// 点击项
export const useHandlerClick = () => {
  const { $MatDialog, $MatToast } = getCurrentInstance()!.appContext.config.globalProperties;
  const listData = ref<ListDataItem[]>(initData); // 列表数据
  // 点击列表
  const onClick = ({ type, tips, message, html, cancelButtonText, confirmButtonText }: ChildListItem) => {
    $MatDialog({
      type,
      tips,
      message,
      html,
      cancelButtonText,
      confirmButtonText,
      onOk(value: string) {
        $MatToast(type === "prompt" ? value : "你点击了确认按钮");
      },
      onOff() {
        $MatToast("你点击了取消按钮");
      }
    });
  };
  return { listData, onClick };
};
